
local unit_class = ac.unit.__index
--创建一个闪电链
function unit_class:create_lightning(data)
    local lightning = data.lightning1 or data.lightning2
    local selector = data.selector
    local target = data.target
    local time = data.time or 0.15
    local fade = data.fade
    local func = data.func
    local count = data.count or 1
    local sum = (data.sum or 0) + 1
    if not selector then
        selector = ac.selector('unit'):enemy(self)
        data.selector = selector
    end
    ac.lightning({
        id = lightning,
        from = self,
        to = target,
        fade = fade,
        time = time,
    })
    ac.wait(time*1000,function()
        if func then
            func(target,sum)
        end
        data.selector = selector:is_not(target)
        local next_unit = count>sum and selector:range(target,data.area or 600):random()
        if next_unit then
            data.sum = sum
            data.target = next_unit
            data.lightning1 = nil
            target:create_lightning(data)
        end
    end)

end